﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Data;
using System.Data.SqlClient;
using Class_Entity;
using System.Web.Configuration;
namespace DataAccess
{
    public class DAQuoteUs
    {
        SqlConnection con;
        SqlCommand cmd;


        public bool Add_QuoteUs(QuoteUs qu)
        {
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spAddQuoteUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@fName", qu.FullName);
                cmd.Parameters.AddWithValue("@cName", qu.CompanyName);
                cmd.Parameters.AddWithValue("@add", qu.Address);
                cmd.Parameters.AddWithValue("@city", qu.City);
                cmd.Parameters.AddWithValue("@state", qu.State);
                cmd.Parameters.AddWithValue("@code", qu.PostalCode);
                cmd.Parameters.AddWithValue("@country", qu.Country);
                cmd.Parameters.AddWithValue("@email", qu.EmailAddress);
                cmd.Parameters.AddWithValue("@phone", qu.Phone);
                cmd.Parameters.AddWithValue("@comments", qu.Comments);



                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return true;
        }


        //-------------------------------------------------------------------------------------------

        public bool Delete_QuoteUs(QuoteUs qu)
        {
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spDeleteQuoteUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@ID", qu.ID);

                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return true;
        }


        //------------------------------------------------------------------------------------------------

        public DataSet Load_QuoteUs(QuoteUs qu)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spLoadQuoteUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.ExecuteNonQuery();

                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }


        //---------------------------------------------------------------------------------------------

        public DataSet Search_QuoteUs(QuoteUs qu)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spSearchQuoteUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@name", qu.FullName);

                cmd.ExecuteNonQuery();

                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }



    }
}
